using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// 外观部位类型
/// </summary>
public enum AppearancePartType
{
    Head,
    Body,
}

public class AppearancePart : MonoBehaviour
{
    public AppearancePartType appearancePartType;

    [SerializeField]
    private SkinnedMeshRenderer skinnedMeshRenderer;

    public void Init()
    {
        skinnedMeshRenderer = GetComponentInChildren<SkinnedMeshRenderer>();
    }

    public void SetAsNewPart(Transform root, Transform[] fullBones)
    {
        transform.SetParent(root);

        var partBones = skinnedMeshRenderer.bones;
        var newPartBones = new List<Transform>();
        for (int i = 0; i < partBones.Length; i++)
        {
            var partBoneName = partBones[i].name;
            for (int j = 0; j < fullBones.Length; j++)
            {
                var bone = fullBones[j];
                if (partBoneName == bone.name)
                {
                    newPartBones.Add(bone);
                }
            }
        }
        skinnedMeshRenderer.bones = newPartBones.ToArray();
    }
}
